// 业务相关hook
import useUserStore from '@/store/modules/user'
import {
  getCompanyById,
  getUserByCompany,
  getAreaByCompanyId,
  getRouteByAreaId,
  getPointByRouteId,
  getAllPointType,
  getRoleApi
} from '@/api/organization/common'
import { getDeviceTagList } from '@/api/device/tag'
import { listDataApi } from '@/api/system/dict/data'
import { allocatedUserList } from '@/api/system/role'
import { getEnterpriseUserMachineList, getMachineList } from '@/api/advert'
import { getAreaList } from '@/api/organization/area'
import { getQueryPointApi } from '@/api/organization/points'
import { getFindPositionDrawApi } from '@/api/lottery'
import { getListCompany } from '@/api/organization/company'

/**
 * 组织管理对接下拉列表api配置
 * @returns
 */
export function useOrganApiConfig() {
  const companyId = useUserStore().companyId

  const apiConfig = reactive({
    company: {
      api: getCompanyById,
      params: { commonId: companyId },
      enableParams: { commonId: companyId, enable: 1 },
      valueField: 'companyId',
      labelField: 'name'
    },
    getCompany: {
      api: getListCompany,
      params: { pageNum: 1, pageSize: 9999 },
      valueField: 'companyId',
      labelField: 'name'
    },
    user: {
      api: getUserByCompany,
      valueField: 'userId',
      labelField: 'nickName',
      roleParams: {
        all: { enable: 1 }, // 全部用户
        area: { type: 'area', enable: 1 }, //线路负责人
        route: { type: 'route', enable: 1 }, //点位负责人
        repair: { type: 'repair', enable: 1 } //设备维修负责人
      }
    },
    area: {
      api: getAreaByCompanyId,
      valueField: 'areaId',
      labelField: 'name'
    },
    route: {
      api: getRouteByAreaId,
      valueField: 'routeId',
      labelField: 'name'
    },
    point: {
      api: getPointByRouteId,
      valueField: 'positionId',
      labelField: 'positionName'
    },
    // 点位类型
    type: {
      api: getAllPointType,
      params: { enable: 1 },
      valueField: 'positionTypeId',
      labelField: 'typeName'
    },
    // 设备标签类型
    tag: {
      api: getDeviceTagList,
      params: { pageSize: 100, pageNum: 1, enable: 1 },
      resultField: 'rows',
      valueField: 'tagId',
      labelField: 'tagName'
    },
    // 角色查询
    role: {
      api: getRoleApi,
      params: { roleId: 1 },
      resultField: 'data',
      valueField: 'userId',
      labelField: 'nickName'
    },
    // 结算周期查询
    settlementCycle: {
      api: listDataApi,
      params: { dictType: 'settlement_cycle' },
      resultField: 'rows',
      valueField: 'dictValue',
      labelField: 'dictLabel'
    },
    // 查询角色已授权用户列表
    allocatedUser: {
      api: allocatedUserList,
      params: { roleId: 1 },
      resultField: 'rows',
      valueField: 'phonenumber',
      labelField: 'nickName'
    },
    // 查询服务商
    provider: {
      api: listDataApi,
      params: { dictType: 'service_provider' },
      resultField: 'rows',
      valueField: 'dictValue',
      labelField: 'dictLabel'
    },
    // 设备查询
    machine: {
      api: getMachineList,
      params: { machineType: 2 },
      valueField: 'machineId',
      labelField: 'machineName'
    },
    // 企业用户单独查询设备列表
    enterpriseUserMachine: {
      api: getEnterpriseUserMachineList,
      params: { machineType: 2 },
      valueField: 'machineId',
      labelField: 'machineName'
    },
    // 企业用户单独查询设备列表
    areaList: {
      api: getAreaList,
      params: { pageNum: 1, pageSize: 9999 },
      resultField: 'rows',
      valueField: 'areaId',
      labelField: 'name'
    },
    getQueryPoint: {
      api: getFindPositionDrawApi,
      valueField: 'positionId',
      labelField: 'positionName'
    }
  })

  return apiConfig
}
